//
//  HOMNSSetCollectTests.m
//  HigherOrderMessaging
//
//  Created by Ofri Wolfus on 14/10/06.
//  Copyright 2006 Ofri Wolfus. All rights reserved.
//

#import "HOMNSSetCollectTests.h"


@implementation HOMNSSetCollectTests

- (id)init {
	if ((self = [super init])) {
		unsigned int i;
		
		msg = [MSG(stringByAppendingString:@"x") retain];
		
		for (i = 0; i < 10000; i++)
			[(NSMutableSet *)largeSetResult addObject:[NSString stringWithFormat:@"%ux", i]];
	}
	
	return self;
}

- (void)dealloc {
	[msg release]; msg = nil;
	[super dealloc];
}

#pragma mark -
#pragma mark Small Set Tests

- (id)testSmallSet {
	return [smallSet collect:MSG(stringByAppendingString:@"x")];
}

- (id)testSmallSet_CachedMessage {
	return [smallSet collect:msg];
}

- (id)testSmallSet_NSEnumerator {
	NSMutableSet *r = [NSMutableSet set];
	NSEnumerator *e = [smallSet objectEnumerator];
	NSString *str;
	
	while ((str = [e nextObject]))
		[r addObject:[str stringByAppendingString:@"x"]];
	
	return r;
}

#pragma mark -
#pragma mark Large Set Tests

- (id)testLargeSet {
	return [largeSet collect:MSG(stringByAppendingString:@"x")];
}

- (id)testLargeSet_CachedMessage {
	return [largeSet collect:msg];
}

- (id)testLargeSet_NSEnumerator {
	NSMutableSet *r = [NSMutableSet set];
	NSEnumerator *e = [largeSet objectEnumerator];
	NSString *str;
	
	while ((str = [e nextObject]))
		[r addObject:[str stringByAppendingString:@"x"]];
	
	return r;
}

#pragma mark -
#pragma mark Tests Verification

- (BOOL)verifyResult:(NSSet *)set ofTest:(SEL)sel {
	NSString *name = NSStringFromSelector(sel);
	
	if ([name hasPrefix:@"testSmallSet"]) {
		DPTestAssert([set count] == 3U, @"The result doesn't contain 3 objects. Result = %@", set);
		DPTestAssert([set containsObject:@"ax"], @"The result doesn't contain 'ax'. Result = %@", set);
		DPTestAssert([set containsObject:@"abcx"], @"The result doesn't contain 'abcx'. Result = %@", set);
		DPTestAssert([set containsObject:@"bx"], @"The result doesn't contain 'bx'. Result = %@", set);
	}
	
	return [super verifyResult:set ofTest:sel];
}

@end
